package org.elsfs.cloud.common.mybatis.ext.sql.support.union;


import lombok.RequiredArgsConstructor;
import org.elsfs.cloud.common.mybatis.ext.sql.UnionType;
import org.elsfs.cloud.common.mybatis.ext.sql.support.builder.StandardSelectSql;

/**
 * 标准联合项实现
 *

 */
@RequiredArgsConstructor
public class StandardUnionItem implements UnionItem {

    /**
     * 查询SQL对象
     */
    private final StandardSelectSql standardSelectSql;
    /**
     * 联合类型
     */
    private final UnionType unionType;

    /**
     * 构建SQL片段
     *
     * @return SQL片段
     */
    @Override
    public String buildSqlFragment() {
        return String.format(
            "%s (%s)",
            this.unionType.getUnionKeyword(),
            this.standardSelectSql.buildSqlFragment()
        );
    }
}
